package com.cgtong.android.mvp.presenter;

import com.cgtong.android.bean.MessageBean;
import com.cgtong.android.mvp.contract.GetMessageContract;
import com.cgtong.android.mvp.model.GetMessageModel;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import java.util.List;

/**
 * Created by Tinwai on 2017/10/24.
 */
public class GetMessagePresenter implements GetMessageContract.Presenter {

    private GetMessageContract.View mView;
    private GetMessageModel model;

    public GetMessagePresenter(GetMessageContract.View mView) {
        this.mView = mView;
        this.model = new GetMessageModel();
    }

    @Override
    public void getUnreadMsg() {
        model.getUnreadMsg(new SimpleCallBack<List<MessageBean>>() {
            @Override
            public void onError(ApiException e) {
                mView.setNullData();
            }

            @Override
            public void onSuccess(List<MessageBean> list) {
                mView.setDatas(list);
            }
        });
    }

    @Override
    public void getMsgList(int type) {
        model.getMsgList(type, new SimpleCallBack<List<MessageBean>>() {
            @Override
            public void onError(ApiException e) {
                mView.setNullData();
            }

            @Override
            public void onSuccess(List<MessageBean> list) {
                if (list == null || list.size() == 0) {
                    mView.setNullData();
                } else {
                    mView.setDatas(list);
                }
            }
        });
    }
}
